using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Collections;
using System.Windows.Forms;

namespace SIMc
{
    /// <summary>
    /// struktura uchovavanie jednotlivych uctov
    /// </summary>
    public struct Account{
        public string uri, password, registrar, proxy, realm;
        public int id;
        public bool use;
    
    }

    /// <summary>
    /// 
    /// </summary>
    public struct Profile
    {
        public string profile_name, profile_password;
        public int ID;
        public bool remember;
        public int default_acc;
        public Account[] accounts;
        public Settings settings;

        public Profile(int ID)
        {
            this.ID = ID;
            this.remember = false;
            this.profile_password = "";
            this.profile_name="";
            this.default_acc = 1;
            this.settings = new Settings();
            this.accounts = new Account[4];
        }

        public void setAccount(Account acc, int index){
            accounts[index]= acc;
        }

        public void setSettings(Settings setting) {
            settings = setting;
        }
    }

    /// <summary>
    /// struktura na uchovavanie nastaveni
    /// </summary>
    public struct Settings{
        public int ID;
        public int profile_ID;
        
    }

    /// <summary>
    /// struktura na uchovavanie kontaktov (pre contactlist)
    /// </summary>
    public struct Contact {
        public string uri, displayName;
        public int ID;
        public int buddyID;
        public string status;
        public string group;
        public int onlineStatus;
    }

    public class XMLWatcher { 
        

        public static ArrayList getPendingWatcher(string watcherInfo){
            XmlDocument xmlDoc = new XmlDocument();
            try
            {
                xmlDoc.LoadXml(watcherInfo);
            }
            catch (Exception e)
            {
                return null;
            }

            ArrayList zoznam = new ArrayList();
            foreach (XmlNode lNode in xmlDoc.DocumentElement.FirstChild.ChildNodes) {
                if (lNode.Attributes["status"].Value.Equals("pending") || lNode.Attributes["status"].Value.Equals("waiting"))
                    zoznam.Add(lNode.InnerText);
            }
            return zoznam;
        }

        public static string getResource(string watcherInfo)
        {
            XmlDocument xmlDoc = new XmlDocument();
            try
            {
                xmlDoc.LoadXml(watcherInfo);
            }
            catch (Exception e)
            {
                return null;
            }

            return xmlDoc.DocumentElement.FirstChild.Attributes["resource"].Value;

            //foreach (XmlNode lNode in xmlDoc.DocumentElement.FirstChild.ChildNodes)
            //{
            //    if (lNode.Attributes["status"].Value.Equals("pending") || lNode.Attributes["status"].Value.Equals("waiting"))
            //        zoznam.Add(lNode.InnerText);
            //}
        }
        
    }
}
